#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*int cmp_int(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int*)p2;
}





void Swap(char*base1 , char*base2,size_t width)
{
	for (int i = 0; i < width; i++)
	{
		int tam = 0;
		tam = *base1;
		*base1 = *base2;
		*base2 = tam;
		base1++;
		base2++;
	}
}


void bubble(void* base, size_t sz, size_t width, int(*cmp)(const void* p1, const void* p2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}


int main()
{
	int arr[10] = { 2,3,5,7,8,9,1,4,6,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble(arr, sz, sizeof(arr[0]), cmp_int);	
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}*/




void Swap(char* base1, char* base2, size_t width)
{
	for (int i = 0; i < width; i++)
	{
		int tam = 0;
		tam = *base1;
		*base1 = *base2;
		*base2 = tam;
		base1++;
		base2++;
	}
}



void qsort(void* base, size_t sz, size_t width, int(*cmp)(const void* p1, const void* p2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
			}
		}
	}
}

int cmp_stu_by_name(const void* p1, const void* p2)
{
	return strcmp(((struct Stu*)p1)->name, ((struct Stu*)p2)->name);
}



int main()
{
	struct Stu
	{
		char name[20];
		int age;
	};
	struct Stu arr[] = { {"zhangsan",20},{"lisi" ,18},{"wangwu",23}};
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_stu_by_name);
}
